package com.example.arcapplication.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

public class ItemInputLayout extends LinearLayout {

//    private ItemInputLayoutBinding binding;

    public ItemInputLayout(Context context) {
        super(context);
    }

    public ItemInputLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public ItemInputLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//        binding = DataBindingUtil.inflate(inflater, R.layout.item_input_layout, this, true);
    }

//    public String getValue() {
//        return binding.getValue();
//    }
//
//    @Override
//    public void setOnClickListener(@Nullable OnClickListener l) {
//        binding.setOnClickListener(l);
//    }
//
//    @BindingAdapter("p_name")
//    public static void setTextName(ItemInputLayout layout, String content) {
//        if (layout != null) {
//            String mCurrentStr = Objects.requireNonNull(layout.binding.tvName.getText()).toString().trim();
//            if (!TextUtils.isEmpty(content)) {
//                if (!content.equalsIgnoreCase(mCurrentStr)) {
//                    layout.binding.tvName.setText(content);
//                }
//            }
//        }
//    }
//
//    @InverseBindingAdapter(attribute = "p_name")
//    public static String getTextName(ItemInputLayout layout) {
//        return Objects.requireNonNull(layout.binding.tvName.getText()).toString().trim();
//    }
//
//    @BindingAdapter("p_value")
//    public static void setTextValue(ItemInputLayout layout, String content) {
//        if (layout != null) {
//            String mCurrentStr = Objects.requireNonNull(layout.binding.evValue.getText()).toString().trim();
//            if (!TextUtils.isEmpty(content)) {
//                if (!content.equalsIgnoreCase(mCurrentStr)) {
//                    layout.binding.evValue.setText(content);
//                    // 设置光标位置
//                    layout.binding.evValue.setSelection(content.length());
//                }
//            }
//        }
//    }
//
//    @InverseBindingAdapter(attribute = "p_value", event = "contentAttrChanged")
//    public static String getTextValue(ItemInputLayout layout) {
//        return Objects.requireNonNull(layout.binding.evValue.getText()).toString().trim();
//    }
//
//    // 监听,如果有变动就调用listener中的onChange方法
//    @BindingAdapter(value = "contentAttrChanged")
//    public static void setChangeListener(ItemInputLayout cetv, InverseBindingListener listener) {
//        cetv.binding.evValue.addTextChangedListener(new TextWatcher() {
//            @Override
//            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//            }
//
//            @Override
//            public void onTextChanged(CharSequence s, int start, int before, int count) {
//                listener.onChange();
//            }
//
//            @Override
//            public void afterTextChanged(Editable s) {
//            }
//        });
//    }
}
